<!--{__NOLAYOUT__}-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="__STATIC__/js/layui/css/layui.css">
</head>
<body>


<div style="margin: 5px;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">登录账号</label>
            <div class="layui-input-inline">
                <input type="text" value="{$user_name}" name="user_name" placeholder="账号" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">请使用邮箱作为账号</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户昵称</label>
            <div class="layui-input-inline">
                <input type="text" name="user_nick" value="{$user_nick}" placeholder="昵称" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">最大长度为15汉字、字母、数字</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-inline">
                <input type="password" name="user_pwd" placeholder="如果不修改请留空" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">密码最小长度为6个字符</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">重复密码</label>
            <div class="layui-input-inline">
                <input type="password" name="user_rpwd" placeholder="如果不修改请留空" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">请重复输入一次密码</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户身份</label>
            <div class="layui-input-inline">
                <select name="user_type" lay-verify="required">
                    <!--<option value=""></option>-->
                    {if condition="$user_type==1"}
                    <option value="0" >普通用户</option>
                    <option value="1" selected>管理员</option>
                    {else /}
                    <option value="0" selected>普通用户</option>
                    <option value="1" >管理员</option>
                    {/if}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">选择用户身份</div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户头像</label>
            <div class="layui-input-inline">
                <img id="header-img" class="layui-nav-img" src="{$user_img}" alt="头像">
                <input type="hidden" value="{$user_img}" name="user_img">
            </div>
            <button type="button" class="layui-btn" id="upload-header">
                <i class="layui-icon">&#xe67c;</i>上传头像
            </button>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<input type="hidden" name="name" value="lalal">
<script src="__STATIC__/js/layui/layui.js" charset="utf-8"></script>
<script src="__STATIC__/js/jquery.min.js" charset="utf-8"></script>


<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload-header' //绑定元素
            ,url: '/admin/usermanagement/upload' //上传接口
            ,accept:'images'
            ,acceptMime:'image/*'
            ,done: function(res){
                //上传完毕回调
                $('#header-img').attr('src', res.data.src);
                $('input[name="user_img"]').val(res.data.src);
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });




    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    layui.use('form', function(){
        var form = layui.form;
        var $ = layui.$;
        //监听提交
        form.on('submit(formDemo)', function(data){
            var postdata = data.field;




            $.ajax({
                type: 'post'
                , dataType: 'json'
                , url: '/admin/usermanagement/edit'
                , data: postdata
                , success: function (obj) {
                    if (obj.code === -1) {
                        layer.msg(obj.msg);
                    } else if (obj.code === 1) {
                        parent.layer.close(index);
                    }

                }
            });
            return false;
        });
    });
</script>
</body>
</html>